import { HTTP } from '@/utils/httpRequestUtil'
import URL from '@/api/api'
export default {
  loadByPaging (params, cb) {
    HTTP.post(URL.CapitalPlanList, params).then(function (response) {
      cb(response.data)
    }).catch(function (error) {
      cb(error.response)
    })
  },
  infoGet (params, cb) {
    console.log("=====params==12======"+params);
    console.log("=====cb==13======"+cb);
    HTTP.post(URL.CapitalPlanGet, params).then(function (response) {
      console.log("=====URL.CapitalPlanGet==15======"+URL.CapitalPlanGet);
      console.log("=====response.data==16======"+response.data);
      cb(response.data)
    }).catch(function (error) {
      cb(error.response)
    })
  },
  infoSave (params, cb) {
    console.log("=====params==23======"+params);
    console.log("=====cb==24======"+cb);
    HTTP.post(URL.CapitalPlanSave, params).then(function (response) {
      console.log("=====URL.CapitalPlanSave==26======"+URL.CapitalPlanSave);
      console.log("=====params.data==27============"+params.data);
      console.log("=====response.data.contract_name==28======"+response.data.contract_name);
      console.log("=====response.data.type==29======"+response.data.type);
      cb(response.data)
    }).catch(function (error) {
      console.log("====error==32======"+error);
      console.log("====error.response==33======"+error.response);
      console.log("====error.response==34======"+error.response.data);
      cb(error.response)
    })
  },
  CapitalPlanImport (fileObj, cb) {
    const formData = new FormData()
    formData.append(fileObj.filename, fileObj.file)
    for (let k in fileObj.param) { // 设置参数
      formData.append(`${k}`, fileObj.param[`${k}`])
    }
    return HTTP.request({
      url: URL.CapitalPlanImport,
      headers: {
        'enctype': 'multipart/form-data',
        'custom-printDebugInfo': 'Y'
      },
      method: 'post',
      data: formData,
    }).then(function (response) {
      cb(response.data)
      // fileObj.onProgress({ percent: 100 })
    }).catch(function (error) {
      cb(error.response)
    })
  },
  CapitalPlanExport (params, cb) {
    HTTP.post(URL.CapitalPlanExport, params).then(function (response) {
      cb(response.data)
    }).catch(function (error) {
      cb(error.response)
    })
  },
}
